package com.wd.elec.controller.utils;

import com.wd.common.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @className: DateTimeUtils
 * @description: TODO 类描述
 * @author: liumingkun
 * @date: 2023/11/16
 **/
public class DateTimeUtils extends DateUtils {

    private final static Logger logger = LoggerFactory.getLogger(DateTimeUtils.class);

    public final static String HH_MM_SS = "HH:mm:ss";

    public final static String HH_MM = "HH:mm";


    public final static String MM = "MM";

    public final static String DD = "dd";

    /**
     * 日期1小于日期2，只比较时间
     *
     * @param startDate
     * @param endDate
     * @return
     */
    public static boolean isBeforeByTime(Date startDate, Date endDate) {
        if (startDate == null || endDate == null) {
            return false;
        }
        SimpleDateFormat timeFormat = new SimpleDateFormat(HH_MM_SS);
        String start = timeFormat.format(startDate);
        String format = timeFormat.format(endDate);
        return start.compareTo(format) < 0;
    }


    /**
     * 日期1小于日期2，只比较时间
     *
     * @param dateString
     * @param dateFormat
     * @return
     */
    public static Date parseToDate(String dateString, String dateFormat) {
        SimpleDateFormat timeFormat = new SimpleDateFormat(dateFormat);
        try {
            return timeFormat.parse(dateString);
        } catch (ParseException e) {
            logger.error(e.getMessage());
            return null;
        }
    }

    /**
     * 获取月份
     * @param date
     * @return
     */
    public static String getMonth(Date date) {
        SimpleDateFormat timeFormat = new SimpleDateFormat(MM);
        return timeFormat.format(date);
    }

    /**
     * 获取日期
     * @param date
     * @return
     */
    public static String getDay(Date date) {
        SimpleDateFormat timeFormat = new SimpleDateFormat(DD);
        return timeFormat.format(date);
    }


    public static void main(String[] args) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(HH_MM);
        try {
            Date parse = simpleDateFormat.parse("05:01");
            System.out.println(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

}
